﻿using Sunny.Core.DefinedData;

namespace Sunny.Core.Domain.Model
{
    public abstract class BaseAggregateRootModel : BaseModel, IAggregateRoot
    {
        public BaseAggregateRootModel(SKey key)
        {
            if(key.IsNull())
            {
                throw  new System.Exception("Key must have a value.");
            }

            this.Key = key;
        }

        #region IAggregateRoot Members

        public virtual SKey Key { get; private set; }

        public bool IsExist
        {
            get { return !this.Key.IsNull() && this.Key > 0; }
        }

        #endregion

        public void SetKey(SKey key)
        {
            this.Key = key;
        }
    }
}
